package com.project.controller.content;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.project.bean.Goods;
import com.project.bean.User;
import com.project.dto.UserDto;
import com.project.service.impl.CartServiceImpl;

@Controller
@RequestMapping("/cart")
public class CartController {
	
	@Autowired
	private CartServiceImpl cartServiceImpl;
	@Autowired
	private HttpSession session;
	@RequestMapping("/getCart")
	public String getCart(ModelMap modelMap){
		if (session.getAttribute("LoginUser")!=null) {
			UserDto loginUser = (UserDto) session.getAttribute("LoginUser");
			List<Goods> cartList = cartServiceImpl.getCart(loginUser);
			modelMap.addAttribute("CartList", cartList);
			return "/cart/cart";
		}else{
			return "/my_account/my_account";
		}

		
	}
	@RequestMapping("/clearCart")
	public String clearCart(){
		UserDto userDto = (UserDto) session.getAttribute("LoginUser");
		cartServiceImpl.clearCart(userDto);
		return "/cart/cart";
	}
}
